//
//  DISBreturnConViewController.m
//  Distributor
//
//  Created by 主事丫环 on 2019/5/10.
//  Copyright © 2019 主事丫环. All rights reserved.
//

#import "DISBreturnConViewController.h"
#import "DISAcomplaintLsitModel.h"

@interface DISBreturnConViewController ()<UIScrollViewDelegate,UITableViewDelegate>
@property(nonatomic,strong)UIScrollView *scrollView;
@property(nonatomic,strong)DISAcomplaintLsitModel *headModel;

@property(nonatomic,strong)UIView *head;

@property(nonatomic,strong)UITextView *mytextview;
@property(nonatomic,strong)UILabel *myplaseLB;

@end

@implementation DISBreturnConViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"投诉详情";
    
    
    self.headModel = [[DISAcomplaintLsitModel alloc]init];
    [self.leftbutton setImage:imgname(@"left_icon") forState:(UIControlStateNormal)];
    //    self.scrollView.contentSize = CGSizeMake(KWIDTH,refaLBddfdf.bottom+20);
    self.view.backgroundColor =  [UIColor colorWithHexString:@"#F2F2F2"];
    
    [self request];
    
}
-(void)request{
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    NSMutableDictionary *param = [NSMutableDictionary dictionaryWithCapacity:1];
    param[@"id"] = NOTNIL(_idStr);
    [NetWorkTool POST:getComplaintInfo param:param success:^(id dic) {
        [DYModelMaker DY_makeModelWithDictionary:[dic objectForKey:@"data"] modelKeyword:@"" modelName:@""];
        [self.headModel setValuesForKeysWithDictionary:[dic objectForKey:@"data"]];
        [self showDetaile];
        
        
    } other:^(id dic) {
        ShowToastWithText(dic[@"msg"]);
    } fail:^(NSError *error) {
        
        
        
    } needUser:YES];
    
    
}
-(void)showDetaile{
    UIView *header = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KWIDTH, 200)];
    CGFloat leftLBwith =57+8;
    CGFloat leftdis =10;
    CGFloat leftLBhei =32;
    
    CGFloat rightwiX = KWIDTH-130;
    
    UILabel *onbg = [[UILabel alloc]initWithFrame:CGRectMake(10, 5, KWIDTH-20, 40)];
    onbg.backgroundColor = [UIColor colorWithHexString:@"#FAFAFA"];
    [header addSubview:onbg];
    
    UILabel *left0 = [[UILabel alloc]initWithFrame:CGRectMake(leftdis, 0, leftLBwith, 40)];
    left0.font = FontSize(14);
    left0.textColor = K666666;
    left0.text = @"投诉主题";
    [onbg addSubview:left0];
    UILabel *center0 = [[UILabel alloc]initWithFrame:CGRectMake(left0.right, 0,rightwiX-20-left0.right, 40)];
    center0.font = FontSize(16);
    center0.textColor = zhutiColor;
    center0.text = _headModel.title;
    [onbg addSubview:center0];
    
    UILabel *right0 = [[UILabel alloc]initWithFrame:CGRectMake(rightwiX-20, 0, 130, 40)];
    right0.font = FontSize(12);
    right0.textColor = zhutiColor;
    right0.text = [NSString stringWithFormat:@"%@",_headModel.createDate];
    [onbg addSubview:right0];
    
    UILabel *line0 = [[UILabel alloc]initWithFrame:CGRectMake(10, onbg.bottom, KWIDTH-20, 1)];
    line0.backgroundColor = [UIColor colorWithHexString:@"#DBDBDB"];
    [header addSubview:line0];
    UILabel *bgtwo = [[UILabel alloc]initWithFrame:CGRectMake(10, line0.bottom, KWIDTH-20, 100)];
    bgtwo.backgroundColor = [UIColor whiteColor];
    [header addSubview:bgtwo];
    header.userInteractionEnabled = YES;
    bgtwo.userInteractionEnabled = YES;
    UILabel *left1 = [[UILabel alloc]initWithFrame:CGRectMake(leftdis, 0, leftLBwith, leftLBhei)];
    left1.font = FontSize(14);
    left1.textColor = K666666;
    left1.text = @"投诉人";
    [bgtwo addSubview:left1];
    UILabel *center1 = [[UILabel alloc]initWithFrame:CGRectMake(left0.right, 0,rightwiX-20-left0.right, leftLBhei)];
    center1.font = FontSize(16);
    center1.textColor = [UIColor colorWithHexString:@"#232620"];
    center1.text = _headModel.user_name;
    [bgtwo addSubview:center1];
    UIButton *right0but = [UIButton buttonWithType:(UIButtonTypeCustom)];
    right0but.frame =CGRectMake(rightwiX-20, 0, 120, leftLBhei);
    [right0but setImage:imgname(@"newPhone") forState:(UIControlStateNormal)];
    [bgtwo addSubview:right0but];
    [right0but setTitleColor:[UIColor colorWithHexString:@"#FFF6A533"] forState:(UIControlStateNormal)];
    [right0but setTitle:@"电话联系" forState:(UIControlStateNormal)];
    right0but.titleLabel.font = FontSize(14);
    [right0but addTarget:self action:@selector(callAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    UILabel *line1 = [[UILabel alloc]initWithFrame:CGRectMake(10, left1.bottom, KWIDTH-30, 1)];
    line1.backgroundColor = [UIColor colorWithHexString:@"#DBDBDB"];
    [bgtwo addSubview:line1];
    
    
    UILabel *left2 = [[UILabel alloc]initWithFrame:CGRectMake(leftdis, line1.bottom, leftLBwith, leftLBhei)];
    left2.font = FontSize(14);
    left2.textColor = K666666;
    left2.text = @"被投诉人";
    [bgtwo addSubview:left2];
    UILabel *center2 = [[UILabel alloc]initWithFrame:CGRectMake(left0.right, line1.bottom,rightwiX-20-left0.right, leftLBhei)];
    center2.font = FontSize(16);
    center2.textColor = [UIColor colorWithHexString:@"#232620"];
    center2.text = _headModel.nickname;
    [bgtwo addSubview:center2];
    UIButton *right1but = [UIButton buttonWithType:(UIButtonTypeCustom)];
    right1but.frame =CGRectMake(rightwiX-20, line1.bottom, 120, leftLBhei);
    [right1but setImage:imgname(@"newPhone") forState:(UIControlStateNormal)];
    [bgtwo addSubview:right1but];
    [right1but setTitleColor:[UIColor colorWithHexString:@"#FFF6A533"] forState:(UIControlStateNormal)];
    [right1but setTitle:@"电话联系" forState:(UIControlStateNormal)];
    right1but.titleLabel.font = FontSize(14);
    [right1but addTarget:self action:@selector(right1butcallAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    UILabel *line2 = [[UILabel alloc]initWithFrame:CGRectMake(10, left2.bottom, KWIDTH-30, 1)];
    line2.backgroundColor = [UIColor colorWithHexString:@"#DBDBDB"];
    [bgtwo addSubview:line2];
    
    
    UILabel *left3 = [[UILabel alloc]initWithFrame:CGRectMake(leftdis, line2.bottom, leftLBwith, leftLBhei)];
    left3.font = FontSize(14);
    left3.textColor = K666666;
    left3.text = @"投诉说明";
    [bgtwo addSubview:left3];
    
    CGFloat fffh = [NSString heightWithWidth:KWIDTH-left0.right-19 font:14 text:_headModel.content];
    if (fffh < leftLBhei) {
        fffh = leftLBhei;
    }
    UILabel *center3 = [[UILabel alloc]initWithFrame:CGRectMake(left0.right, line2.bottom,KWIDTH-left0.right-19, fffh)];
    center3.font = FontSize(14);
    center3.textColor = [UIColor colorWithHexString:@"#232620"];
    center3.text = _headModel.content;
    center3.numberOfLines = 0;
    [bgtwo addSubview:center3];
    
    bgtwo.height = center3.bottom;
    
    header.height = bgtwo.bottom+2;
    [self.scrollView addSubview:header];
    self.head = header;
    
    
     UILabel *bglb = [[UILabel alloc]initWithFrame:CGRectMake(10, _head.bottom+5, KWIDTH-20, 139)];
     bglb.backgroundColor = [UIColor whiteColor];
     bglb.userInteractionEnabled = YES;
     UILabel *left22 = [[UILabel alloc]initWithFrame:CGRectMake(10, 14, KWIDTH-100, 16)];
     left22.font = FontSize(16);
     left22.textColor = [UIColor colorWithHexString:@"#232620"];
     left22.text = @"回复详情:";
     [bglb addSubview:left22];
     
     UITextView *mytextview = [[UITextView alloc]initWithFrame:CGRectMake(10, 40, KWIDTH-40, 85)];
     
     mytextview.backgroundColor = [UIColor colorWithHexString:@"F2F2F2"];
     mytextview.layer.masksToBounds = YES;
     mytextview.layer.cornerRadius = 4;
     [bglb addSubview:mytextview];
     mytextview.delegate = self;
     self.mytextview = mytextview;
     
     UILabel *plLb = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, KWIDTH-60, 16)];
     plLb.font = FontSize(16);
     plLb.textColor = [UIColor colorWithHexString:@"#979797"];
     plLb.text = @"在这里输入处理结果哦";
     [self.mytextview addSubview:plLb];
     self.myplaseLB = plLb;
     [self.scrollView addSubview:bglb];
     
     
     UIButton *gochulibut = [UIButton buttonWithType:(UIButtonTypeCustom)];
     [gochulibut setBackgroundColor:zhutiColor];
     [gochulibut setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
     
     CGFloat  ffff = KHEIGHT - 230;
     if (ffff <  bglb.height+50) {
     ffff =bglb.height+50;
     }
     
     gochulibut.frame = CGRectMake(28, ffff, KWIDTH-28-28, 48);
     [gochulibut setTitle:@"提交" forState:(UIControlStateNormal)];
     gochulibut.layer.masksToBounds = YES;
     gochulibut.layer.cornerRadius = 4;
     [gochulibut addTarget:self action:@selector(goaction:) forControlEvents:(UIControlEventTouchUpInside)];
     
     [self.scrollView addSubview:gochulibut];
     self.scrollView.contentSize = CGSizeMake(KWIDTH, gochulibut.bottom);
     [self.view addSubview:self.scrollView];
     
     self.scrollView.contentSize = CGSizeMake(KWIDTH, gochulibut.bottom);
     
     
    
    if ([_isshow isEqualToString:@"show"]) {
        self.myplaseLB.hidden = YES;
        self.mytextview.text = _headModel.handleContent;
        gochulibut.hidden = YES;
    }
    
    
    [MBProgressHUD hideHUDForView:self.view animated:YES];
}
-(void)goaction:(UIButton *)but{
    if (strIsEmpty(_mytextview.text)) {
        ShowToastWithText(@"请输入有效回复");
        return;
    }
    
    NSMutableDictionary *param = [NSMutableDictionary dictionaryWithCapacity:1];
    param[@"id"] = NOTNIL(_idStr);
    param[@"content"] = _mytextview.text;

    kWeakSelf;
    
    [NetWorkTool POST:handleComplaintret param:param success:^(id dic) {
        
        ZSTipsView *view = [ZSTipsView new];
        view.upLable.text = @"提交成功";
        [view.btn setTitle:@"完成" forState:(UIControlStateNormal)];
        view.btnBlock = ^{
            if (weakSelf.myblock) {
                weakSelf.myblock(@"");
            }
            [weakSelf.navigationController popViewControllerAnimated:YES];
        };
        [view show];
        
    } other:^(id dic) {
        ShowToastWithText(dic[@"msg"]);
    } fail:^(NSError *error) {
        
    } needUser:YES];
    
    
   
}
-(void)callAction:(UIButton *)but{
    [HFTools callMobilePhone:_headModel.phone];
}
-(void)right1butcallAction:(UIButton *)but{
    [HFTools callMobilePhone:_headModel.repPhone];
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
    self.myplaseLB.hidden = YES;
    
    return YES;
}
- (UIScrollView *)scrollView {
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, kNaviHeight, KWIDTH, KHEIGHT-kNaviHeight)];
        _scrollView.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
        
        _scrollView.delegate = self;
        adjustInset(_scrollView);
    }
    return _scrollView;
}

@end
